﻿Imports System.Globalization
Imports Microsoft.VisualStudio.TestTools.UnitTesting

<TestClass>
Public Class ExceptionFactoryTest

#Region "CreateException"
    <TestMethod>
    Public Sub CreateException_HResultExists_SPERR_RECOERROR_NOSPEECH()
        Dim hrTest = SpeechHResults.SPERR_RECOERROR_NOSPEECH

        Dim ex = New MockException(hrTest)

        Dim actual = ExceptionFactory.CreateException(ex)

        Assert.IsNotNull(actual)
        Assert.IsInstanceOfType(actual, GetType(SpeechException))
        Assert.IsTrue(actual.HResult = hrTest)
        Assert.IsTrue(CType(actual, SpeechException).ErrorCode = "SPERR_RECOERROR_NOSPEECH")
        Assert.AreSame(actual.InnerException, ex)
    End Sub

    <TestMethod>
    Public Sub CreateException_HResultNotExists()
        Dim hrTest = -10000

        Dim ex = New MockException(hrTest)

        Dim actual = ExceptionFactory.CreateException(ex)

        Assert.IsNotNull(actual)
        Assert.IsNotInstanceOfType(actual, GetType(SpeechException))
        Assert.IsTrue(actual.HResult = hrTest)
        Assert.AreSame(actual, ex)
    End Sub
#End Region


    Private Class MockException
        Inherits Exception

        Public Sub New(hresult As Integer)
            Me.HResult = hresult
        End Sub
    End Class
End Class
